function deepCopy<T extends object>(obj: T): T {
    if (typeof obj !== 'object' || obj === null) {
        return obj;
    }
    let result: Array<any> | object = Array.isArray(obj) ? [] : {};
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            (result as { [key: string]: any })[key] = deepCopy((obj as { [key: string]: any })[key]);
        }
    }
    return result as T;
}
